﻿using UnityEngine.InputSystem;

public class PlayerStoppingState : PlayerGroundedState
{
    public PlayerStoppingState(PlayerMovementMachine stateMachine) : base(stateMachine)
    {
    }

#region IState Methods
    public override void Enter()
    {
        base.Enter();
        StateMachine.ReusableData.MovementSpeedModify = 0;
        StartAnimation(StateMachine.Player.AnimationData.StoppingParameterHash);
    }
    
    public override void PhysicUpdate()
    {
        base.PhysicUpdate();
        
        RotateTowardsTargetRotation();
        
        if (!IsMovingHorizontally())
        {
            return;
        }
        
        DecelerateHorizontally();
    }

    public override void OnAnimationTransitionEvent()
    {
        StateMachine.ChangeState(StateMachine.IdlingState);
    }

    public override void Exit()
    {
        base.Exit();
        StopAnimation(StateMachine.Player.AnimationData.StoppingParameterHash);
    }
#endregion

#region Reusable Methods
    protected override void AddInputActionsCallBacks()
    {
        base.AddInputActionsCallBacks();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.started += OnMovementStarted;
    }

    protected override void RemoveInputActionsCallBacks()
    {
        base.RemoveInputActionsCallBacks();
        StateMachine.Player.PlayerInput.PlayerActions.Movement.started -= OnMovementStarted;
    }
#endregion
    

#region Input Methods
    protected override void OnMovementCanceled(InputAction.CallbackContext context)
    {
    }

    private void OnMovementStarted(InputAction.CallbackContext context)
    {
        OnMove();
    }
#endregion

}